package com.hy.cloud.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hy.cloud.order.entity.Order;
import com.hy.cloud.order.entity.User;
import com.hy.cloud.order.service.OrderService;
import com.hy.cloud.order.mapper.OrderMapper;
import com.hy.cloud.order.service.UserRpcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Random;

/**
 * @author Administrator
 * @description 针对表【tb_order】的数据库操作Service实现
 * @createDate 2025-10-21 11:06:53
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
        implements OrderService {

    private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Order findOrderByOrderId(Long orderId) {
        Order order = orderMapper.selectOrderByOrderId(orderId);

        User user = restTemplate.getForObject("http://my-cloud-user/api/user/findUserByUserId/" + order.getUserId(), User.class);

        order.setUser(user);

        return order;
    }

}